package request;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;

/**
 * 请求转发：一种在服务器内部的资源跳转方式，从一个servlet中跳转到另一个servlet中
 * myRequest7跳转到myRequest8
 *
 * 特点：
 *   1. 浏览器地址栏路径不发生变化
 *   2. 只能转发到当前服务器内部资源中
 *   3. 转发是一次请求
 * 域数据的存储
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-20-21:18 21:18
 */
@WebServlet("/myRequest7")
public class MyRequest7 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("myRequest7被访问了....");
        //setAttribute(String name,Object obj):通过域进行共享数据进行存储
        request.setAttribute("name","chai");

        //跳转到/myRequest5的doGet
        /*RequestDispatcher requestDispatcher = request.getRequestDispatcher("/myRequest5");
        requestDispatcher.forward(request,response);*/

        request.getRequestDispatcher("/myRequest8").forward(request,response);
    }
}
